package com.ssy.lingxi.purchase.entity.onlinebidding;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.purchase.api.dto.request.EnclosureUrlsRequest;
import com.ssy.lingxi.purchase.entity.bidding.Bidding;
import com.ssy.lingxi.purchase.entity.converter.JpaJsonToEnclosureUrlsRequestListConverter;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.List;

/**
 *在线竞价实体
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "pu_on_line_bidding")
public class OnLineBidding {
        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "on_line_bidding_seq")
        @SequenceGenerator(sequenceName = "pu_on_line_bidding_seq", name = "on_line_bidding_seq", allocationSize = 1)
        private Long id;

        /**
         * 采购竞价信息
         */
        @JsonBackReference
        @OneToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
        @JoinColumn(name = "bidding_id", referencedColumnName = "id")
        private Bidding bidding;

        /**
         *竞价单编号
         */
        private String biddingNo;

        /**
         * 竞价供应商信息
         */
        @JsonManagedReference
        @OneToMany(mappedBy = "onlineBidding", cascade = {CascadeType.PERSIST, CascadeType.MERGE})
        private List<OnlineMateriel> materiels;

        /**
         * 单据时间
         */
        private Long createTime;

        /**
         * 最后修改时间
         */
        private Long updateTime;

        /**
         *是否发送中标通知 1.是 0.否
         */
        private Integer prizeNotice;

        /**
         *是否发送发送感谢函 1.是 0.否
         */
        private Integer thank;

        /**
         *是否发布中标公告 1.是 0.否
         */
        private Integer notice;

        /**
         *中标公告内容
         */
        private String awardResults;

        /**
         *感谢函内容
         */
        private String content;

        /**
         *授标意见
         */
        private String signUpIdea;

        /**
         *有效竞标次数
         */
        private Long count=0L;

        /**
         *最终授标总额(含税)
         */
        private Double sumAwardPrice;

        /**
         * 授标会员
         */
        private Long memberId;

        /**
         * 授标会员
         */
        private Long memberRoleId;

        /**
         * 授标会员
         */
        private String memberName;

        /**
         * 授标结果附件
         */
        @Convert(converter = JpaJsonToEnclosureUrlsRequestListConverter.class)
        @Column(columnDefinition = "jsonb")
        private List<EnclosureUrlsRequest> returnUrls;

        /**
         * 外部状态共用状态  个人外部状态在 OnlineMateriel
         */
        private Integer externalState;

        /**
         * 内部流转(所有供应商共用状态) 个人内部状态在 OnlineMateriel
         * 待竞价报名(需要所有参与竞价报名的供应商全部通过审核 或者报名时间到期(前提是有人报名, 不然直接作废), 才会进入下一步) -> 已竞价报名
         * 待竞价(需要所有参与竞价的供应商全部竞价完毕 或者竞价时间到期(前提是有人竞价, 不然直接作废), 才会进入下一步) -> 已竞价
         */
        private Integer interiorState;
}
